package com.ruoyi.logistic.service.impl;

import com.github.pagehelper.PageHelper;
import com.ruoyi.logistic.domain.*;
import com.ruoyi.logistic.domain.vo.NetworkOutboundGoAnalyzeVo;
import com.ruoyi.logistic.domain.vo.NetworkOutboundGoVo;
import com.ruoyi.logistic.mapper.NetworkNameMapper;
import com.ruoyi.logistic.mapper.NetworkOutboundGoAnalyzeMapper;
import com.ruoyi.logistic.mapper.NetworkOutboundGoCollectMapper;
import com.ruoyi.logistic.mapper.NetworkOutboundGoDetailMapper;
import com.ruoyi.logistic.service.NetworkOutboundGoDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Service
public class NetworkOutboundGoDetailServiceImpl implements NetworkOutboundGoDetailService {
    @Autowired
    private NetworkOutboundGoDetailMapper networkOutboundGoDetailMapper;
    @Autowired
    private NetworkOutboundGoCollectMapper networkOutboundGoCollectMapper;
    @Autowired
    private NetworkOutboundGoAnalyzeMapper networkOutboundGoAnalyzeMapper;
    @Autowired
    private NetworkNameMapper networkNameMapper;

    @Override
    public List<NetworkOutboundGoDetail> selectAll(PageDate pageDate) {
        PageHelper.startPage(pageDate);
        return networkOutboundGoDetailMapper.selectAll();
    }

    @Override
    public Boolean insert(NetworkOutboundGoDetail networkOutboundGoDetail) {
        return networkOutboundGoDetailMapper.insert(networkOutboundGoDetail);
    }

    @Override
    public Boolean update(NetworkOutboundGoDetail networkOutboundGoDetail) {
        return networkOutboundGoDetailMapper.update(networkOutboundGoDetail);
    }

    @Override
    public Boolean deleteById(Integer id) {
        return networkOutboundGoDetailMapper.deleteById(id);
    }

    @Override
    public List<NetworkOutboundGoDetail> search(NetworkOutboundGoVo networkOutboundGoVo) {
        PageHelper.startPage(networkOutboundGoVo.getPageDate());
        List<NetworkOutboundGoDetail> details = networkOutboundGoDetailMapper.search(networkOutboundGoVo);
//        for (NetworkOutboundGoDetail detail : details){
////            detail.setNetworkName(networkNameMapper.selectNameById(detail.getNetworkNameId()));
////            detail.setSignNetworkName(networkNameMapper.selectNameById(detail.getReceiveSiteName()));
//        }
        return details;
    }

    @Override
    public List<NetworkOutboundGoCollect> outboundGoCollect(NetworkOutboundGoVo networkOutboundGoVo) {
        PageHelper.startPage(networkOutboundGoVo.getPageDate());
        List<NetworkOutboundGoCollect> details = networkOutboundGoCollectMapper.outboundGoCollect(networkOutboundGoVo);
//        for (NetworkOutboundGoCollect collect : details){
//            collect.setNetworkName(networkNameMapper.selectNameById(collect.getNetworkNameId()));
//        }
        return details;
    }

    @Override
    public NetworkOutboundGoAnalyzeAll collectAnalyze(NetworkOutboundGoAnalyzeVo networkOutboundGoAnalyzeVo) {
        List<NetworkOutboundGoAnalyze> list = networkOutboundGoAnalyzeMapper.collectAnalyze(networkOutboundGoAnalyzeVo);

        List<String> provinceList = new ArrayList<>();
        List<Integer> countList = new ArrayList<>();
        List<BigDecimal> incomeList = new ArrayList<>();

        for (NetworkOutboundGoAnalyze obj : list) {
            provinceList.add(obj.getProvince());
            countList.add(obj.getCount());
            incomeList.add(obj.getIncome());
        }

// 然后将集合转换为数组
        String[] provinces = provinceList.toArray(new String[0]);
        Integer[] counts = countList.toArray(new Integer[0]);
        BigDecimal[] incomes = incomeList.toArray(new BigDecimal[0]);

// 创建并初始化新对象
        NetworkOutboundGoAnalyzeAll analyzeAll = new NetworkOutboundGoAnalyzeAll();
        analyzeAll.setProvince(provinces);
        analyzeAll.setCount(counts);
        analyzeAll.setIncome(incomes);
        return analyzeAll;
    }
}
